package com.copro.chemdb.stat.rule.export;

import java.util.List;
import java.util.Map;

import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.ihelpuoo.util.Properties;

import com.copro.chemdb.stat.ExportRule;
import com.copro.chemdb.stat.StatResult;
import com.copro.chemdb.subject.Subject;
import com.copro.simple.Application;
import com.copro.simple.SimpleException;

public class Rule5 implements ExportRule {

	@SuppressWarnings("unchecked")
	@Override
	public void doExport(HSSFWorkbook wb, Subject subject, StatResult re,
			short customStyle, Application app) throws SimpleException {
		Map<String, Object> result = (Map<String, Object>) re.getResult();
		// create new sheet
		HSSFSheet sheet = wb.createSheet("专题数据库所属行业");
		// set the header
		HSSFRow row = null;
		int rowN = 0;

		List<Map<String, Object>> bussSet = (List<Map<String, Object>>) result
				.get("bussSet");
		for (int i = 0; i < bussSet.size(); i++) {
			Map<String, Object> header = (Map<String, Object>) bussSet.get(i)
					.get("header");
			row = sheet.createRow(rowN);
			rowN++;
			CellUtil.createCell(row, 0, "行业: " + header.get("name"), wb
					.getCellStyleAt((short) (customStyle + StyleHeader)));
			CellUtil.createCell(row, 1, "数据库数量: " + header.get("count"), wb
					.getCellStyleAt((short) (customStyle + StyleHeaderInt)));
			List<Map<String, Object>> bodys = (List<Map<String, Object>>) bussSet
					.get(i).get("bodys");
			for (int j = 0; j < bodys.size(); j++) {
				Map<String, Object> body = bodys.get(j);
				row = sheet.createRow(rowN);
				rowN++;
				CellUtil.createCell(row, 0, (String) body.get("comName"));
				CellUtil.createCell(row, 1, (String) body.get("dbNames"));
			}
		}
	}

	@Override
	public void setup(Properties conf) {
	}

}
